home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / RECT.C < prev    next >
Text File  |  1991-10-02  |  3KB  |  96 lines

  1. /* ------------- rect.c --------------- */
  2.  
  3. #include <dos.h>
  4. #include "dflat.h"
  5.  
  6.  /* --- Produce the vector end points produced by the overlap
  7.         of two other vectors --- */
  8. static void subVector(int *v1, int *v2,
  9.                         int t1, int t2, int o1, int o2)
  10. {
  11.     *v1 = *v2 = -1;
  12.     if (within(o1, t1, t2))    {
  13.         *v1 = o1;
  14.         if (within(o2, t1, t2))
  15.             *v2 = o2;
  16.         else
  17.             *v2 = t2;
  18.     }
  19.     else if (within(o2, t1, t2))    {
  20.         *v2 = o2;
  21.         if (within(o1, t1, t2))
  22.             *v1 = o1;
  23.         else
  24.             *v1 = t1;
  25.     }
  26.     else if (within(t1, o1, o2))    {
  27.         *v1 = t1;
  28.         if (within(t2, o1, o2))
  29.             *v2 = t2;
  30.         else
  31.             *v2 = o2;
  32.     }
  33.     else if (within(t2, o1, o2))    {
  34.         *v2 = t2;
  35.         if (within(t1, o1, o2))
  36.             *v1 = t1;
  37.         else
  38.             *v1 = o1;
  39.     }
  40. }
  41.  
  42.  /* --- Return the rectangle produced by the overlap
  43.         of two other rectangles ---- */
  44. RECT subRectangle(RECT r1, RECT r2)
  45. {
  46.     RECT r = {0,0,0,0};
  47.     subVector((int *) &RectLeft(r), (int *) &RectRight(r),
  48.         RectLeft(r1), RectRight(r1),
  49.         RectLeft(r2), RectRight(r2));
  50.     subVector((int *) &RectTop(r), (int *) &RectBottom(r),
  51.         RectTop(r1), RectBottom(r1),
  52.         RectTop(r2), RectBottom(r2));
  53.     if (RectRight(r) == -1 || RectTop(r) == -1)
  54.         RectRight(r) =
  55.         RectLeft(r) =
  56.         RectTop(r) =
  57.         RectBottom(r) = 0;
  58.     return r;
  59. }
  60.  
  61. /* ------- return the client rectangle of a window ------ */
  62. RECT ClientRect(void *wnd)
  63. {
  64.     RECT rc;
  65.  
  66.     RectLeft(rc) = GetClientLeft((WINDOW)wnd);
  67.     RectTop(rc) = GetClientTop((WINDOW)wnd);
  68.     RectRight(rc) = GetClientRight((WINDOW)wnd);
  69.     RectBottom(rc) = GetClientBottom((WINDOW)wnd);
  70.     return rc;
  71. }
  72.  
  73. /* ----- return the rectangle relative to
  74.             its window's screen position -------- */
  75. RECT RelativeWindowRect(void *wnd, RECT rc)
  76. {
  77.     RectLeft(rc) -= GetLeft((WINDOW)wnd);
  78.     RectRight(rc) -= GetLeft((WINDOW)wnd);
  79.     RectTop(rc) -= GetTop((WINDOW)wnd);
  80.     RectBottom(rc) -= GetTop((WINDOW)wnd);
  81.     return rc;
  82. }
  83.  
  84. /* ----- clip a rectangle to the parents of the window ----- */
  85. RECT ClipRectangle(void *wnd, RECT rc)
  86. {
  87.     RECT sr;
  88.     RectLeft(sr) = RectTop(sr) = 0;
  89.     RectRight(sr) = SCREENWIDTH-1;
  90.     RectBottom(sr) = SCREENHEIGHT-1;
  91.     if (!TestAttribute((WINDOW)wnd, NOCLIP))
  92.         while ((wnd = GetParent((WINDOW)wnd)) != NULLWND)
  93.             rc = subRectangle(rc, ClientRect(wnd));
  94.     return subRectangle(rc, sr);
  95. }
  96.